#include "stone.h"
#include"gamecontrol.h"

Stone::Stone()
{
    this->setPixmap(QPixmap(":/1/Image/Stone.png"));
    this->setPos(520,340);
}

void Stone::Move()
{
    QRectF mManBlueRect = QRectF(GameControl::Instance()->getManBlue().x()+35,GameControl::Instance()->getManBlue().y()+25,35,50);

    QRectF mManRedRect = QRectF(GameControl::Instance()->getManRed().x()+25,GameControl::Instance()->getManRed().y()+25,40,50);

    QRectF stone = QRectF(this->boundingRect().translated(this->pos()));

    if(mManBlueRect.intersects(stone))
    {
        for(int i=0;i< GameControl::Instance()->mKeyList.size();i++)
        {
            switch( GameControl::Instance()->mKeyList[i])
            {
            case Qt::Key_W:
            {
                break;
            }
            case Qt::Key_S:
            {
                break;
            }
            case Qt::Key_A:
            {
                this->moveBy(-1 * mMoveSpeed,0);
                break;
            }
            case Qt::Key_D:
            {
                this->moveBy(1*mMoveSpeed,0);
                break;
            }
            }
        }
    }

    if(mManRedRect.intersects(stone))
    {
        for(int i=0;i< GameControl::Instance()->mKeyList.size();i++)
        {
            switch( GameControl::Instance()->mKeyList[i])
            {
            case Qt::Key_5:
            {
                break;
            }
            case Qt::Key_1://左
            {
                this->moveBy(-1 * mMoveSpeed,0);
                break;
            }
            case Qt::Key_2:
            {
                break;
            }
            case Qt::Key_3://右
            {
                this->moveBy(1*mMoveSpeed,0);
                break;
            }
            }
        }
    }

    QRectF mPlayer = QRectF(this->x(),this->y(),this->boundingRect().width(),this->boundingRect().height());

    for(int i=0;i<GameControl::Instance()->wallsLeft.size();i++)
    {
        if(mPlayer.intersects(GameControl::Instance()->wallsLeft[i]))
        {
            this->setX(GameControl::Instance()->wallsLeft[i].x()+10);
            break;
        }
    }

    for(int i=0;i<GameControl::Instance()->wallsRight.size();i++)
    {
        if(mPlayer.intersects(GameControl::Instance()->wallsRight[i]))
        {
            this->setX(GameControl::Instance()->wallsRight[i].x()-50);
            break;
        }
    }
}
void Stone::stoneCollisions(){}

void Stone::updatePosition(){}

void Stone::detectCollisions(){}

void Stone::diamondCollisions(){}

void Stone::water(){}

void Stone::changePixmap(){}

void Stone::strategyCollision(){}

Stone::~Stone(){}
